package com.woniuxy.jmm;

import com.woniuxy.untis.Sleep;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/4/8:15:07
 * <P> Description:
 */
@SuppressWarnings("all")
public class Test1 {

    static boolean flag = true;
    /**
     *
     * TODO 也可以用 synchronized 实现可见性 不过可见的属性 都要在 synchronized 代码块中
     */
    final static Object lock = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            while (true) {
                synchronized (lock) {
                    if (!flag) {
                        break;
                    }
                }
            }
        }).start();

        Sleep.sleep(100);
        synchronized (lock) {
            flag = false;
        }
        System.out.println("Test1.main");
    }

    public void t1(){

    }
}
